﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using DTD2013.Common;

namespace DTD2013.DTDComponent
{
    public partial class DTDTextEditControl : TextEdit
    {
        public DTDTextEditControl()
        {
            InitializeComponent();
            InitializeControl();
        }

        public DTDTextEditControl(IContainer container) : this()
        {
            container.Add(this);
        }

        private void InitializeControl()
        {
            this.FontHeight = 12;
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(DTDTextEditControl_KeyUp);
        }

        private void DTDTextEditControl_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.C)
            {
                Clipboard.SetText(this.SelectedText, TextDataFormat.Text);
            }
            else if (e.Control && e.KeyCode == Keys.V)
            {
                int selectionStart = this.SelectionStart;
                string insertText = Clipboard.GetText(TextDataFormat.Text);
                this.Text = this.Text.Insert(this.SelectionStart, insertText);
                this.SelectionStart = selectionStart + insertText.Length;
            }
            else if (e.KeyCode == Keys.Enter)
            {
                SendKeys.Send(SymbolCode.KEY_TAB);
            }
        }
    }
}
